<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="parentId">
        <p>111</p>
        <p class="test">222</p>
        <p>333</p>
        <p>444</p>
    </div>

    <script>
       const divObj = document.getElementById("parentId")
       console.log(divObj)

      const test = divObj.getElementsByClassName('test')
      console.log(test)     //HTMLCollection [p.test]

      //获取第一个元素
      const testTarget = divObj.getElementsByClassName("test")[0]
      console.log(testTarget)
      console.log(testTarget.innerText)
    </script>
</body>
</html>